package PacoteTestes;
 

 
import org.hibernate.Session;
 
import org.hibernate.Transaction;
 
import org.junit.AfterClass;
 
import org.junit.BeforeClass;
 

 
import br.com.loja.util.HibernateUtil;
 

 
public abstract class Conexao {
 
        
 
        private static Session sessao;
 
        private static Transaction transacao;
 

 
        @BeforeClass
 
        public  static void abreConexao() {
 
                sessao = HibernateUtil.getSession().getCurrentSession();
 
                transacao = sessao.beginTransaction();
 
        }
 

 
        @AfterClass
 
        public static void fechaConexao() {
 

 
                try {
 

 
                        transacao.commit();
 

 
                } catch (Throwable e) {
 
                        System.out.println("deu problema no commit : " + e.getMessage());
 
                } finally {
 
                        try {
 
                                if (sessao.isOpen()) {
 
                                        sessao.close();
 
                                }
 
                        } catch (Exception e2) {
 
                                System.out.println("Deu erro no fechamanto da sesso"+ e2.getMessage());
 
                        }
 

 
                }
 
        }
 

 
        public static Session getSessao() {
 
                return sessao;
 
        }
 

 
        public static void setSessao(Session sessao) {
 
                Conexao.sessao = sessao;
 
        }
 

 
        public static Transaction getTransacao() {
 
                return transacao;
 
        }
 

 
        public static void setTransacao(Transaction transacao) {
 
                Conexao.transacao = transacao;
 
        }
 
        
 
        
 
        
 
}
 
